/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.squirrelm.my.dao.impl;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import java.util.List;
import javax.jdo.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.squirrelm.my.PersistenceManagerHolder;
import org.squirrelm.my.dao.JipiaoDao;
import org.squirrelm.my.domain.Jipiao;

/**
 *
 * @author 松鼠M
 */
@Repository
public class JipiaoDaoImpl implements JipiaoDao {

    private final PersistenceManagerHolder ppx;

    @Autowired
    public JipiaoDaoImpl(PersistenceManagerHolder ppx)
    {
        this.ppx    = ppx;
    }

    private DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

    public void create(Jipiao jipiao) {
        ppx.get().makePersistent(jipiao);
    }

    public List<Jipiao> find(int offset, int num) {
        Query   q   = ppx.get().newQuery(Jipiao.class);
        q.setRange(offset, num + offset);
        q.setOrdering("fetchTime desc");
        return (List<Jipiao>) q.execute(false);
    }

}
